﻿using OA.Core;
using OA.Model.MyAttribute;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace OA.Model
{
    /// <summary>
    /// 协同
    /// </summary>
    [Table("SynergyForm")]
    public class SynergyForm
    {

        [Key]
        [Display(Name = "ID")]
        public int ID { get; set; }

        /// <summary>
        /// -1 被删除 0 草稿  1 协同中 2:协同完成
        /// </summary>
        [Display(Name = "状态")]
        [Description("-1 被删除 0 草稿  1 未审核 2:正在审核中 4 审核不通过 8 已审核")]
        public int Status { get; set; }

        /// <summary>
        /// 创建日期
        /// </summary>
        [Display(Name = "创建日期")]
        public DateTime CreateDateTime { get; set; }


        /// <summary>
        /// 协作发起时间
        /// </summary>
        [Display(Name = "协作发起时间")]
        public DateTime? LaunchDateTime { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Display(Name = "名称")]
        [MaxLength(50)]
        [Required]
        [Tag(TagEnum.Text, "required", "名称", 10, 50)]
        public string Name { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
       // [Index(name: "EmpID", IsClustered = false, IsUnique = false, Order = 1)]
        [Display(Name = "创建人")]
        [MaxLength(10)]
        [Required(ErrorMessage = "不能为空")]
        [Tag(TagEnum.Text, "required", "创建人", 3, 10)]
        public string EmpID { get; set; }

         
        /// <summary>
        /// 扩展字段
        /// </summary>
        [Display(Name = "扩展字段")]
        public string ExtendField { get; set; }


        [NotMapped]
        public List<ExtendField> ListExtendField { get; set; }

        [NotMapped]
        public List<ExtendField> TableFields { get; set; }

        [NotMapped]
        public List<CountersignEmployee> SynergyEmployees
        {
            get;set;
        }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }


        /// <summary>
        /// 协作成员
        /// </summary>
        [Display(Name = "协作成员")]
        public string SynergyEmpID { get; set; }


        public string SynergyEmployeesContent { get; set; }

        /// <summary>
        /// 当前操作人
        /// </summary>
        [MaxLength(10)]
        public string CurrentEditor { get; set; }

        /// <summary>
        /// 共享成人
        /// </summary>
        public string SharedMember { get; set; }

        /// <summary>
        /// 历史版本
        /// </summary>
        public string Versions { get; set; }

        [MaxLength(20)]
        public string CurrentEditorName { get; set; }

        [MaxLength(20)]
        public string EmpName { get; set; }

    }

    public class SynergyFormVersions
    {
        //public ExtensionResultInfo ResultInfo { get; set; }

        public string Editor { get; set; }

        public string EditorName { get; set; }

        public DateTime EditTime { get; set; }

    }

    public class SimpleSynergyForm
    {
        [Key]
        [Display(Name = "ID")]
        public int ID { get; set; }

        /// <summary>
        /// -1 被删除 0 草稿  1 协同中 2:协同完成
        /// </summary>
        [Display(Name = "状态")]
        [Description("-1 被删除 0 草稿  1 未审核 2:正在审核中 4 审核不通过 8 已审核")]
        public int Status { get; set; }

        [NotMapped]
        public string StatusName
        {
            get
            {
                if (this.Status == 0)
                {
                    return "草稿";
                }
                else if (this.Status == 1)
                {
                    return "协同中";
                }
                else if (this.Status == 2)
                {
                    return "协同完成";
                }
                else
                {
                    return string.Empty;
                }
            }
        }

        /// <summary>
        /// 协作发起时间
        /// </summary>
        [Display(Name = "协作发起时间")]
        public DateTime? LaunchDateTime { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Display(Name = "名称")]
        [MaxLength(50)]
        [Required]
        [Tag(TagEnum.Text, "required", "名称", 10, 50)]
        public string Name { get; set; }


       // [Index(name: "EmpID", IsClustered = false, IsUnique = true, Order = 1)]
        [Display(Name = "创始人")]
        [MaxLength(10)]
        [Required(ErrorMessage = "不能为空")]
        [Tag(TagEnum.Text, "required", "创始人", 3, 10)]
        public string EmpID { get; set; }

        [MaxLength(20)]
        public string EmpName { get; set; }


        /// <summary>
        /// 协同人
        /// </summary>
        public string SynergyEmpID { get; set; }

        /// <summary>
        /// 当前操作人
        /// </summary>
        [MaxLength(10)]
        public string CurrentEditor { get; set; }

        [MaxLength(20)]
        public string CurrentEditorName { get; set; }

        public static Expression<Func<SynergyForm, SimpleSynergyForm>> Map = m => new SimpleSynergyForm()
        {
            ID = m.ID,
            LaunchDateTime = m.LaunchDateTime,
            CurrentEditor = m.CurrentEditor,
            EmpID = m.EmpID,
            Name = m.Name,
            Status = m.Status,
            SynergyEmpID = m.SynergyEmpID,
            EmpName = m.EmpName,
            CurrentEditorName = m.CurrentEditorName
        };


    }
}
